/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.latesis.dao.hibernate;

import com.latesis.bean.AlertaBean;
import com.latesis.bean.PropietarioBean;
import com.latesis.dao.AlertaDAO;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author acabrera
 */
@Transactional(propagation=Propagation.SUPPORTS)
public class AlertaDAOHibernateImpl extends HibernateDaoSupport implements AlertaDAO{
    public AlertaBean guardar(AlertaBean bean) {
         getHibernateTemplate().saveOrUpdate(bean);
         return bean;
    }

    public void borrar(AlertaBean bean) {
        getHibernateTemplate().delete(bean) ;
    }

    public AlertaBean buscar(AlertaBean bean) {
        return getHibernateTemplate().get(AlertaBean.class, bean.getId());
    }

    public List<AlertaBean> buscarTodos() {
        return (List<AlertaBean>)getHibernateTemplate().find("from AlertaBean ");
    }
    
    public List<AlertaBean> buscarCustom(int start, int end) {
        Query q = getSession().createQuery("from AlertaBean where estado = 'A' ");
        q.setMaxResults(end-start);
        q.setFirstResult(start);
        return (List<AlertaBean>)q.list();
        
    }
    
    public int countTotal(){
        Query query = getSession().createQuery("SELECT COUNT(u) FROM AlertaBean u");
        Number result = (Number)query.uniqueResult();
        return result.intValue();
    }
}
